package ui.faces.kitchen.renderer
{
	import events.GestureEvent;
	
	import flash.text.TextField;
	
	import global.Managers;
	
	import ui.components.Button;
	import ui.components.renderlist.AbstractRenderer;
	import ui.faces.kitchen.vo.UnconfirmedRendererVO;
	import ui.prompt.PromptBox;
	
	import utils.StringUtil;
	import utils.TextUtil;
	
	import vo.DishVO;

	public class UnconfirmedRenderer extends AbstractRenderer
	{
		private var _txtContent					: TextField;
		private var _btnConfirm					: Button;
		
		public function UnconfirmedRenderer()
		{
			super();
		}
		override protected function createBg():void {
			super.createBg();
			
			with(_bg.graphics) {
				lineStyle(1);
				beginFill(0xffffff, 1);
				drawRect(0, 0, 420, 40);
				endFill();
			}
		}
		override protected function createView():void {
			super.createView();
			
			_txtContent = TextUtil.getTextFieldEasy(" ");
			_txtContent.x = 5;
			_txtContent.y = (_bg.height - _txtContent.height) / 2;
			addChild(_txtContent);
			
			_btnConfirm = new Button(0, Managers.languageManager.getLanguageText("confirm_making"), 80, 30, "", confirmHandler);
			_btnConfirm.x = 405;
			_btnConfirm.y = (_bg.height - _btnConfirm.height) / 2;
			_btnConfirm.addListener(Managers.faceManager.kitchenFace);
			addChild(_btnConfirm);
		}
		override protected function updateView():void {
			super.updateView();
			
			var listVO:UnconfirmedRendererVO = _listVO as UnconfirmedRendererVO;
			var dishVO:DishVO = Managers.dishManager.getValueByID(listVO.dishID);
			_txtContent.text = StringUtil.format("No.{0}: {1}({2})", listVO.tableID, dishVO.name, listVO.dishID);
		}
		private function confirmHandler(event:GestureEvent):void {
			PromptBox.confirm(Managers.languageManager.getLanguageText("confirm_making_confirm"), "", function():void {
				var listVO:UnconfirmedRendererVO = _listVO as UnconfirmedRendererVO;
				Managers.serverManager.send("KitchenConfirmDishes", [listVO.orderID]);
			});
		}
	}
}